using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Input.Touch;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;


namespace amazingfishing
{
    /// <summary>
    /// 这是一个实现 IUpdateable 的游戏组件。
    /// </summary>
    public class WorldMap : Microsoft.Xna.Framework.DrawableGameComponent
    {
        protected Texture2D mapTexture;//地图
        private SpriteBatch spriteBatch;
        Button scene1;
        Button scene2;
        Button scene3;

       // Button scene1;

        public WorldMap(Game game)
            : base(game)
        {
            // TODO: 在此处构造任何子组件
        }

        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(Game.GraphicsDevice);
            mapTexture = Game.Content.Load<Texture2D>(@"images\map");
            scene1 = new Button(Game.Content.Load<Texture2D>(@"images\scene\ice"),Vector2.Zero);
            scene1.todoEvent += setScene_ice;
            scene2 = new Button(Game.Content.Load<Texture2D>(@"images\scene\river"), new Vector2(0, 236));
            scene2.todoEvent += setScene_river;
            scene3 = new Button(Game.Content.Load<Texture2D>(@"images\scene\sea"), new Vector2(0, 517));
            scene3.todoEvent += setScene_sea;



            base.LoadContent();
        }

        void scene1_todoEvent()
        {
                throw new NotImplementedException();
        }

        /// <summary>
        /// 允许游戏组件在开始运行之前执行其所需的任何初始化。
        /// 游戏组件能够在此时查询任何所需服务和加载内容。
        /// </summary>
        public override void Initialize()
        {
            // TODO: 在此处添加初始化代码

            base.Initialize();
        }

        /// <summary>
        /// 允许游戏组件进行自我更新。
        /// </summary>
        /// <param name="gameTime">提供计时值的快照。</param>
        public override void Update(GameTime gameTime)
        {
            // TODO: 在此处添加更新代码
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                ((Game1)Game).currentState = Game1.GameState.on_menu;

            GestureSample gs;
            if (TouchPanel.IsGestureAvailable)
            {
                gs = TouchPanel.ReadGesture();
                scene1.checkClick(gs.Position);
                scene2.checkClick(gs.Position);
                scene3.checkClick(gs.Position);
            }
            base.Update(gameTime);
        }

        public override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.AliceBlue);

            spriteBatch.Begin();
            spriteBatch.Draw(mapTexture, new Rectangle(0, 0, 480, 800), null, Color.White);

            if (!(((Game1)Game).currentState == Game1.GameState.scene1))
                scene1.Draw(gameTime, spriteBatch);
            if (!(((Game1)Game).currentState == Game1.GameState.scene2))
             scene2.Draw(gameTime, spriteBatch);
            if(!(((Game1)Game).currentState == Game1.GameState.scene3))
                scene3.Draw(gameTime, spriteBatch);

            spriteBatch.End();

            base.Draw(gameTime);
        }
        void setScene_ice()
        {
            ((Game1)Game).currentState = Game1.GameState.scene1;
        }
        void setScene_river()
        {
            ((Game1)Game).currentState = Game1.GameState.scene2;
        }
        void setScene_sea()
        {
            ((Game1)Game).currentState = Game1.GameState.scene3;
        }
    }
}
